<?php
/* @var $this SuratKeluarController */
/* @var $model SuratKeluar */

$this->breadcrumbs=array(
	'Surat Keluar'=>array('index'),
	'Create',
);
?>

<?php 
$js = <<< EOF_JS
function beforeValidate(form) {
    
    var Pegawai= $('.items tbody tr').size();
    
    if(Pegawai<=0){
        alert('Data Persetujuan masih kosong');
        return false;
    }
 
    return true;
}
EOF_JS;
Yii::app()->clientScript->registerScript('penerimaan-tamu-form-beforeValidate', $js);

echo $this->renderPartial('_form', array('model'=>$model,'title' => 'Create SuratKeluar')); 
                             
                                    Yii::app()->clientScript->registerScript(
                                            'add_approval', 
                                            "
                                                var update='';
                                                $('.update').live('click', function(){
                                                    var id = $(this).attr('rel');
                                                    $('#tipe_identitas').val($('#tipe_identitas_'+id).val());
                                                    $('#no_identitas').val($('#no_identitas_'+id).val());
                                                    update = id;
                                                });
                                                
                                                $('.delete').live('click', function(){
                                                    var id = $(this).attr('rel');
                                                    $('.items tbody #'+id).replaceWith('');
                                                });

                                                function addPegawai(ui){
                                                        
                                                        if(update!=''){
                                                            var rowId = update;
                                                        }else{
                                                            var rowId = '';
                                                            $('.items tbody tr').each(function(i, l){
                                                                rowId = parseInt($(this).attr('id'))+1;
                                                            });
                                                            if(rowId=='')
                                                                rowId = parseInt($('.items tbody tr').size())+1;
                                                        }
                                                        
                                                        var row = '<tr class=\'row\' id='+ rowId +'>';
                                                            row += '<td>'+ui.item.label+'</td>';
                                                            row += '<input type=\'hidden\' id=pegawai_'+ rowId +' name=pegawai['+ rowId +'] value='+ ui.item.id_pegawai +' />';
                                                            row += '<td>'+ui.item.struktur_organisasi+'</td>';
                                                            row += '<td class=\'lastcolumn\'>';    
                                                            row +=   '<a  title=\'Uprdate\' rel='+ rowId +' class=\'update\'>';
                                                            row +=      '<img alt=\'Update\' src=\'/images/icon/update.png\'>';
                                                            row +=   '</a>'; 
                                                            row +=   '<a  title=\'Delete\' rel='+ rowId +' class=\'delete\'>';
                                                            row +=       '<img alt=\'Delete\' src=\'/images/icon/delete.png\'>';
                                                            row +=    '</a>';
                                                            row +=  '</td>';
                                                            row += '</tr>';
                                                            
                                                            if(update!=''){
                                                                $('.items tbody #'+update).replaceWith(row);
                                                            }else{
                                                                $('.items tbody').append(row);
                                                            }
                                                    
                                                };
                                            ", 
                                            CClientScript::POS_END);
                                    
?>